package servlet;

import bean.User;
import dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author guoxiuwei
 * @Date 2020/8/24 18:59
 * @Title
 */
@WebServlet("/passwordUpdate")
public class passwordUpdate extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码为utf8
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        //String uname = request.getParameter("uanme");
        String oldPasswrodre = request.getParameter("oldPassword");
        String newPassword = request.getParameter("newPassword");
        HttpSession session = request.getSession(false);
        User u = (User)session.getAttribute("us");
        String uname = u.getUname();
        //System.out.println(uname+"->"+oldPasswrodre+"->"+newPassword);



        boolean isSuccess = new UserDaoImpl().passwordUpdate(uname,oldPasswrodre,newPassword);
        if (isSuccess){
//            response.getWriter().println("密码修改成功");
            System.out.println("密码修改成功");
        }else {
//            response.getWriter().println("密码修改失败");
        }



    }
}
